﻿#include "clock.h"
#include <QQmlEngine>
#include <QQmlFileSelector>
#include <QMessageBox>
#include <QQmlError>
#include <QCoreApplication>
#include <QQuickView>

Clock::Clock()
{
	view = new QQuickView();
}

Clock::~Clock()
{
	if (view) {
        delete view;
		view = NULL;
	}
}

void Clock::Excute(const char* content)
{
    QString str = QString::fromLocal8Bit(content);
    if(str.contains(QStringLiteral("电子钟"))){
        QMessageBox::about(NULL,"",QStringLiteral("抱歉，没有电子钟哦"));
    }
    view->connect(view->engine(), &QQmlEngine::quit, qApp, &QCoreApplication::quit);
	view->setSource(QUrl("qrc:/clocks/clocks.qml"));
    if (view->status() == QQuickView::Error){
        QMessageBox::about(NULL,"",view->errors()[0].toString());
        return;
    }
	view->setResizeMode(QQuickView::SizeRootObjectToView);
	view->show();
}
